<?php
class ControllerModuleArticleAllSettings extends Controller {
	private $error = array(); 
	
	public function index() {   
		$this->load->language('module/article_all_settings');
			$this->load->model('news/install');		
			$this->model_news_install->checkInstall();		
			$this->checkWrite();
		$this->document->setTitle($this->language->get('heading_title'));
		$this->getForm();
	}
	
	public function settings() {   
		$this->load->language('module/article_all_settings');
		$this->document->setTitle($this->language->get('heading_title'));
		
		$this->load->model('setting/setting');
				
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
			$this->model_setting_setting->editSetting('article_all_settings', $this->request->post);		
					
			$this->session->data['success'] = $this->language->get('text_success');
						
			$this->redirect($this->url->link('module/article_all_settings/info', 'token=' . $this->session->data['token'], 'SSL'));
		}
			$this->getForm();
	}
	public function info(){			
		$this->load->language('module/article_all_settings');
	
		$this->data['heading_title'] = $this->language->get('heading_title');
		
		$this->data['text_setting'] = $this->language->get('text_setting');
		$this->data['text_uninstall'] = $this->language->get('text_uninstall');
		$this->data['text_optimize_db'] = $this->language->get('text_optimize_db');
		$this->data['text_optimize'] = $this->language->get('text_optimize');
		$this->data['text_empty'] = $this->language->get('text_empty');
		$this->data['text_drop'] = $this->language->get('text_drop');
		$this->data['text_uninstall_module'] = $this->language->get('text_uninstall_module');
		$this->data['text_empty_db'] = $this->language->get('text_empty_db');
		$this->data['text_install'] = $this->language->get('text_install');
		$this->data['text_sample'] = $this->language->get('text_sample');
		$this->data['text_drop_db'] = $this->language->get('text_drop_db');
		$this->data['text_article_type'] = $this->language->get('text_article_type');
		$this->data['text_author'] = $this->language->get('text_author');
		$this->data['text_download'] = $this->language->get('text_download');
		$this->data['text_comment'] = $this->language->get('text_comment');
		
		$this->data['text_confirm'] = $this->language->get('text_confirm');
		$this->data['text_confirm_empty'] = $this->language->get('text_confirm_empty');
		$this->data['text_confirm_drop'] = $this->language->get('text_confirm_drop');
		
		$this->data['sample']=$this->url->link('module/article_all_settings/install_sample','token='.$this->session->data['token'], 'SSL');
		$this->data['uninstall_module']=$this->url->link('module/article_all_settings/uninstall_module','token='.$this->session->data['token'], 'SSL');
		$this->data['optimize']=$this->url->link('module/article_all_settings/optimize','token='.$this->session->data['token'], 'SSL');
		$this->data['empty_db']=$this->url->link('module/article_all_settings/empty_db','token='.$this->session->data['token'], 'SSL');
		$this->data['drop_db']=$this->url->link('module/article_all_settings/drop_db','token='.$this->session->data['token'], 'SSL');
		
		$this->data['setting'] = $this->url->link('module/article_all_settings/settings', 'token=' . $this->session->data['token'], 'SSL');
		$this->data['category'] = $this->url->link('news/category', 'token=' . $this->session->data['token'], 'SSL');
		$this->data['article'] = $this->url->link('news/article', 'token=' . $this->session->data['token'], 'SSL');
		$this->data['author'] = $this->url->link('news/author', 'token=' . $this->session->data['token'], 'SSL');
		$this->data['download'] = $this->url->link('news/download', 'token=' . $this->session->data['token'], 'SSL');
		$this->data['comment'] = $this->url->link('news/comment', 'token=' . $this->session->data['token'], 'SSL');
		$this->data['poll'] = $this->url->link('news/poll', 'token=' . $this->session->data['token'], 'SSL');		
		$this->data['general'] = $this->url->link('module/article_all_settings', 'token=' . $this->session->data['token'], 'SSL');	
			
		$this->data['button_cancel'] = $this->language->get('button_cancel');			
		$this->data['text_news_overview'] = $this->language->get('text_news_overview');
		$this->data['text_total_category'] = $this->language->get('text_total_category');
		$this->data['text_total_article'] = $this->language->get('text_total_article');
		$this->data['text_total_author'] = $this->language->get('text_total_author');
		$this->data['text_total_download'] = $this->language->get('text_total_download');
		$this->data['text_total_comment'] = $this->language->get('text_total_comment');
		$this->data['text_total_poll'] = $this->language->get('text_total_poll');
		$this->data['text_total_comment_awaiting'] = $this->language->get('text_total_comment_awaiting');
		$this->data['text_empty_db'] = $this->language->get('text_empty_db');
		$this->data['text_drop_db'] = $this->language->get('text_drop_db');
		
		$this->load->model('news/category');
		$this->load->model('news/article');

		$this->load->model('news/author');
		$this->load->model('news/comment');
		$this->load->model('news/download');
		$this->load->model('news/poll');
		
		$this->data['total_category'] = $this->model_news_category->getTotalCategories();
		$this->data['total_article'] = $this->model_news_article->getTotalArticle();
		$this->data['total_author'] = $this->model_news_author->getTotalAuthors();
		$this->data['total_download'] = $this->model_news_download->getTotalDownloads();
		$this->data['total_comment'] = $this->model_news_comment->getTotalComments();
		$this->data['total_comment_awaiting'] = $this->model_news_comment->getTotalCommentsAwaitingApproval();
		$this->data['total_poll'] = $this->model_news_poll->getTotalPolls();
		
		/*Success*/ 
		if (isset($this->session->data['success'])) {
			$this->data['success'] = $this->session->data['success'];
		
			unset($this->session->data['success']);
		} else {
			$this->data['success'] = '';
		}
		/*Error*/ 
		
		
  		$this->data['breadcrumbs'] = array();

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => false
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_module'),
			'href'      => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
		
   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('module/article_all_settings', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
		
		$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');

		$this->template = 'module/article_setting_main.tpl';
		$this->children = array(
			'common/header',
			'news/shortcut_route',
			'news/shortcut_module',
			'common/footer'
		);;
				
		$this->response->setOutput($this->render());
	}
	
	private function getForm(){			
		$this->load->model('news/install');		
		$this->model_news_install->checkInstall();				
		$this->data['heading_title'] = $this->language->get('heading_title');
		$this->data['text_publish'] = $this->language->get('text_publish');		
		$this->data['text_unpublish'] = $this->language->get('text_unpublish');		
		$this->data['text_enabled'] = $this->language->get('text_enabled');		
		$this->data['text_disabled'] = $this->language->get('text_disabled');
		$this->data['text_yes'] = $this->language->get('text_yes');		
		$this->data['text_no'] = $this->language->get('text_no');
		
		$this->data['text_content_top'] = $this->language->get('text_content_top');
		$this->data['text_content_bottom'] = $this->language->get('text_content_bottom');		
		$this->data['text_column_left'] = $this->language->get('text_column_left');
		$this->data['text_column_right'] = $this->language->get('text_column_right');
		$this->data['text_refine_search'] = $this->language->get('text_refine_search');		
		$this->data['text_related_category'] = $this->language->get('text_related_category');
		
		$this->data['text_description'] = $this->language->get('text_description');
		$this->data['text_image_size'] = $this->language->get('text_image_size');
		$this->data['text_date_format'] = $this->language->get('text_date_format');
		$this->data['text_comment'] = $this->language->get('text_comment');
		$this->data['text_confirm'] = $this->language->get('text_confirm');
		$this->data['text_author_setting'] = $this->language->get('text_author_setting');
		$this->data['text_none'] = $this->language->get('text_none');
		$this->data['text_multi'] = $this->language->get('text_multi');
		$this->data['text_single'] = $this->language->get('text_single');
		
        
        $this->data['text_sort_date']    = $this->language->get('text_sort_date');
		$this->data['text_sort_name']     = $this->language->get('text_sort_name');
		$this->data['text_sort_order']     = $this->language->get('text_sort_order');
		$this->data['text_sort_viewed']   = $this->language->get('text_sort_viewed');
		$this->data['text_sort_rating']   = $this->language->get('text_sort_rating');
		$this->data['text_sort_author']    = $this->language->get('text_sort_author');
		$this->data['text_order_desc']   = $this->language->get('text_order_desc');
		$this->data['text_order_asc']   = $this->language->get('text_order_asc');
		 
		$this->data['entry_code'] = $this->language->get('entry_code');
		$this->data['entry_layout'] = $this->language->get('entry_layout');
		$this->data['entry_position'] = $this->language->get('entry_position');
		$this->data['entry_status'] = $this->language->get('entry_status');
		$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
		
		$this->data['button_save'] = $this->language->get('button_save');
		$this->data['button_cancel'] = $this->language->get('button_cancel');
		$this->data['button_add_module'] = $this->language->get('button_add_module');
		$this->data['button_remove'] = $this->language->get('button_remove');
		

		
		$this->data['entry_author_account'] = $this->language->get('entry_author_account');
		$this->data['entry_upload_allowed'] = $this->language->get('entry_upload_allowed');
		$this->data['entry_login_to_download'] = $this->language->get('entry_login_to_download');
		$this->data['entry_article_category'] = $this->language->get('entry_article_category');
		$this->data['entry_image_column'] = $this->language->get('entry_image_column');
		$this->data['entry_article_thumb'] = $this->language->get('entry_article_thumb');
		$this->data['entry_article_popup'] = $this->language->get('entry_article_popup');
		$this->data['entry_image_article'] = $this->language->get('entry_image_article');
		$this->data['entry_article_additional'] = $this->language->get('entry_article_additional');
		$this->data['entry_article_related'] = $this->language->get('entry_article_related');
		$this->data['entry_article_description_limit'] = $this->language->get('entry_article_description_limit');
		$this->data['entry_author_upload_allowed'] = $this->language->get('entry_author_upload_allowed');
		$this->data['entry_username_not_allowed'] = $this->language->get('entry_username_not_allowed');
		$this->data['entry_author_article_status'] = $this->language->get('entry_author_article_status');
		$this->data['entry_author_article_approved'] = $this->language->get('entry_author_article_approved');
		$this->data['entry_author_register_status'] = $this->language->get('entry_author_register_status');
		$this->data['entry_author_approved'] = $this->language->get('entry_author_approved');
		$this->data['entry_article_to_category'] = $this->language->get('entry_article_to_category');
		$this->data['entry_reference_canonical'] = $this->language->get('entry_reference_canonical');
		$this->data['entry_notification_email'] = $this->language->get('entry_notification_email');
		$this->data['entry_notification_mail'] = $this->language->get('entry_notification_mail');
		$this->data['entry_author_delete_permission'] = $this->language->get('entry_author_delete_permission');
		$this->data['entry_display_refer'] = $this->language->get('entry_display_refer');
		$this->data['entry_comment_email'] = $this->language->get('entry_comment_email');
		$this->data['entry_comment_email'] = $this->language->get('entry_comment_email');
		
		$this->data['entry_default_article_sort'] = $this->language->get('entry_default_article_sort');
		$this->data['entry_default_article_order'] = $this->language->get('entry_default_article_order');
		
		$this->data['entry_desc_help']   = $this->language->get('entry_desc_help');
		$this->data['entry_asc_help']   = $this->language->get('entry_asc_help');
		
		$this->data['entry_free_download'] = $this->language->get('entry_free_download');
		$this->data['entry_comment'] = $this->language->get('entry_comment');
		$this->data['entry_comment_approved'] = $this->language->get('entry_comment_approved');
		$this->data['entry_article_date_format'] = $this->language->get('entry_article_date_format');
		$this->data['entry_related_description_limit'] = $this->language->get('entry_related_description_limit');
		$this->data['entry_related_article_limit'] = $this->language->get('entry_related_article_limit');
		$this->data['entry_related_children_limit'] = $this->language->get('entry_related_children_limit');
		$this->data['entry_related_catalog_image_size'] = $this->language->get('entry_related_catalog_image_size');
		$this->data['entry_related_catalog_position'] = $this->language->get('entry_related_catalog_position');
		$this->data['entry_related_catalog_status'] = $this->language->get('entry_related_catalog_status');
		
		/*Success*/ 
		if (isset($this->session->data['success'])) {
			$this->data['success'] = $this->session->data['success'];
		
			unset($this->session->data['success']);
		} else {
			$this->data['success'] = '';
		}
		/*Error*/ 
 		if (isset($this->error['warning'])) {
			$this->data['error_warning'] = $this->error['warning'];
		} else {
			$this->data['error_warning'] = '';
		}
		
		if (isset($this->error['article_description_limit'])) {
			$this->data['error_article_description_limit'] = $this->error['article_description_limit'];
		} else {
			$this->data['error_article_description_limit'] = '';
		}
		if (isset($this->error['image_column'])) {
			$this->data['error_image_column'] = $this->error['image_column'];
		} else {
			$this->data['error_image_column'] = '';
		}
		
		if (isset($this->error['image_article'])) {
			$this->data['error_image_article'] = $this->error['image_article'];
		} else {
			$this->data['error_image_article'] = '';
		}
		if (isset($this->error['image_article_category'])) {
			$this->data['error_image_article_category'] = $this->error['image_article_category'];
		} else {
			$this->data['error_image_article_category'] = '';
		}
				
 		if (isset($this->error['image_article_thumb'])) {
			$this->data['error_image_article_thumb'] = $this->error['image_article_thumb'];
		} else {
			$this->data['error_image_article_thumb'] = '';
		}
		
 		if (isset($this->error['image_article_popup'])) {
			$this->data['error_image_article_popup'] = $this->error['image_article_popup'];
		} else {
			$this->data['error_image_article_popup'] = '';
		}
		
 		if (isset($this->error['image_article_additional'])) {
			$this->data['error_image_article_additional'] = $this->error['image_article_additional'];
		} else {
			$this->data['error_image_article_additional'] = '';
		}	
		
 		if (isset($this->error['image_article_related'])) {
			$this->data['error_image_article_related'] = $this->error['image_article_related'];
		} else {
			$this->data['error_image_article_related'] = '';
		}
		
		if (isset($this->error['email'])) {
			$this->data['error_email'] = $this->error['email'];
		} else {
			$this->data['error_email'] = '';
		}
		
  		$this->data['breadcrumbs'] = array();

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_home'),
			'href'      => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => false
   		);

   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('text_module'),
			'href'      => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
		
   		$this->data['breadcrumbs'][] = array(
       		'text'      => $this->language->get('heading_title'),
			'href'      => $this->url->link('module/article_all_settings', 'token=' . $this->session->data['token'], 'SSL'),
      		'separator' => ' :: '
   		);
		
		$this->data['token'] = $this->session->data['token'];
		$this->data['action'] = $this->url->link('module/article_all_settings/settings', 'token=' . $this->session->data['token'], 'SSL');
		
		$this->data['cancel'] = $this->url->link('module/article_all_settings', 'token=' . $this->session->data['token'], 'SSL');
		
		$this->data['button_sample'] = $this->language->get('button_sample');
		$this->data['sample']=$this->url->link('module/article_all_settings/install_sample','token='.$this->session->data['token'], 'SSL');
		$this->data['hide_sample']=$this->url->link('module/article_all_settings/hide_sample','token='.$this->session->data['token'], 'SSL');
		/*Related Catalog Settings*/ 		
		if (isset($this->request->post['config_related_catalog_status'])) {
			$this->data['config_related_catalog_status'] = $this->request->post['config_related_catalog_status'];
		}   else {
			$this->data['config_related_catalog_status'] = $this->config->get('config_related_catalog_status');
		}
				
		if (isset($this->request->post['config_related_description_limit'])) {
			$this->data['config_related_description_limit'] = $this->request->post['config_related_description_limit'];
		} elseif ($this->config->get('config_related_description_limit')) {
			$this->data['config_related_description_limit'] = $this->config->get('config_related_description_limit');
		}else {
			$this->data['config_related_description_limit'] = 255;
		}		
		if (isset($this->request->post['config_related_article_limit'])) {
			$this->data['config_related_article_limit'] = $this->request->post['config_related_article_limit'];
		} elseif ($this->config->get('config_related_article_limit')) {
			$this->data['config_related_article_limit'] = $this->config->get('config_related_article_limit');
		} else {
			$this->data['config_related_article_limit'] = 1;
		}
		if (isset($this->request->post['config_related_children_limit'])) {
			$this->data['config_related_children_limit'] = $this->request->post['config_related_children_limit'];
		} elseif ($this->config->get('config_related_children_limit')) {
			$this->data['config_related_children_limit'] = $this->config->get('config_related_children_limit');
		}  else {
			$this->data['config_related_children_limit'] = 0;
		}
		
		if (isset($this->request->post['config_related_catalog_image_width'])) {
			$this->data['config_related_catalog_image_width'] = $this->request->post['config_related_catalog_image_width'];
		} elseif ($this->config->get('config_related_catalog_image_width')) {
			$this->data['config_related_catalog_image_width'] = $this->config->get('config_related_catalog_image_width');
		}  else {
			$this->data['config_related_catalog_image_width'] = 150;
		}
		
		if (isset($this->request->post['config_related_catalog_image_height'])) {
			$this->data['config_related_catalog_image_height'] = $this->request->post['config_related_catalog_image_height'];
		} elseif ($this->config->get('config_related_catalog_image_height')) {
			$this->data['config_related_catalog_image_height'] = $this->config->get('config_related_catalog_image_height');
		}  else {
			$this->data['config_related_catalog_image_height'] = 112;
		}
		
		if (isset($this->request->post['config_related_catalog_position'])) {
			$this->data['config_related_catalog_position'] = $this->request->post['config_related_catalog_position'];
		} elseif ($this->config->get('config_related_catalog_position')) {
			$this->data['config_related_catalog_position'] = $this->config->get('config_related_catalog_position');
		}  else {
			$this->data['config_related_catalog_position'] = 'content_top';
		}
		
		/*Author Settings*/ 
		
		if (isset($this->request->post['config_news_canonical'])) {
			$this->data['config_news_canonical'] = $this->request->post['config_news_canonical'];
		}  elseif ($this->config->get('config_news_canonical')) {
			$this->data['config_news_canonical'] = $this->config->get('config_news_canonical');
		} else {
			$this->data['config_news_canonical'] = HTTP_CATALOG;
		}
		
		if (isset($this->request->post['config_notification_mail'])) {
			$this->data['config_notification_mail'] = $this->request->post['config_notification_mail'];
		} else {
			$this->data['config_notification_mail'] = $this->config->get('config_notification_mail');
		}
		
		if (isset($this->request->post['config_notification_email'])) {
			$this->data['config_notification_email'] = $this->request->post['config_notification_email'];
		}  elseif ($this->config->get('config_notification_email')) {
			$this->data['config_notification_email'] = $this->config->get('config_notification_email');
		}   else {
			$this->data['config_notification_email'] = $this->config->get('config_email');
		} 
		
		$this->load->model('catalog/information');		
		$this->data['informations'] = $this->model_catalog_information->getInformations();
					
		if (isset($this->request->post['config_author_account_id'])) {
			$this->data['config_author_account_id'] = $this->request->post['config_author_account_id'];
		} else {
			$this->data['config_author_account_id'] = $this->config->get('config_author_account_id');			
		}
		
		
		if (isset($this->request->post['config_author_upload_allowed'])) {
			$this->data['config_author_upload_allowed'] = $this->request->post['config_author_upload_allowed'];
		} else {
			$this->data['config_author_upload_allowed'] = $this->config->get('config_author_upload_allowed');
		}	
		
		if (isset($this->request->post['config_username_not_allowed'])) {
			$this->data['config_username_not_allowed'] = $this->request->post['config_username_not_allowed'];
		} else {
			$this->data['config_username_not_allowed'] = $this->config->get('config_username_not_allowed');
		}
		
		if (isset($this->request->post['config_author_register_status'])) {
			$this->data['config_author_register_status'] = $this->request->post['config_author_register_status'];
		} else {
			$this->data['config_author_register_status'] = $this->config->get('config_author_register_status');
		}
		if (isset($this->request->post['config_author_approved'])) {
			$this->data['config_author_approved'] = $this->request->post['config_author_approved'];
		} else {
			$this->data['config_author_approved'] = $this->config->get('config_author_approved');
		}
		
		if (isset($this->request->post['config_author_article_status'])) {
			$this->data['config_author_article_status'] = $this->request->post['config_author_article_status'];
		} else {
			$this->data['config_author_article_status'] = $this->config->get('config_author_article_status');
		}
		
		if (isset($this->request->post['config_author_article_approved'])) {
			$this->data['config_author_article_approved'] = $this->request->post['config_author_article_approved'];
		} else {
			$this->data['config_author_article_approved'] = $this->config->get('config_author_article_approved');
		}
		if (isset($this->request->post['config_author_permission'])) {
			$this->data['config_author_permission'] = $this->request->post['config_author_permission'];
		} else {
			$this->data['config_author_permission'] = $this->config->get('config_author_permission');
		}
		if (isset($this->request->post['config_display_refer'])) {
			$this->data['config_display_refer'] = $this->request->post['config_display_refer'];
		} else {
			$this->data['config_display_refer'] = $this->config->get('config_display_refer');
		}
		
		if (isset($this->request->post['config_article_category'])) {
			$this->data['config_article_category'] = $this->request->post['config_article_category'];
		} else {
			$this->data['config_article_category'] = $this->config->get('config_article_category');
		}
	/*General Settings*/ 
	
		if (isset($this->request->post['config_news_sample_installed'])) {
			$this->data['config_news_sample_installed'] = $this->request->post['config_news_sample_installed'];
		} else {
			$this->data['config_news_sample_installed'] = $this->config->get('config_news_sample_installed');
		}
		if (isset($this->request->post['config_news_installed'])) {
			$this->data['config_news_installed'] = $this->request->post['config_news_installed'];
		} else {
			$this->data['config_news_installed'] = $this->config->get('config_news_installed');
		}
		
		/*Article*/ 
		if (isset($this->request->post['config_article_sort'])) {
			$this->data['config_article_sort'] = $this->request->post['config_article_sort'];
		} else {
			$this->data['config_article_sort'] = $this->config->get('config_article_sort');
		}
		if (isset($this->request->post['config_article_order'])) {
			$this->data['config_article_order'] = $this->request->post['config_article_order'];
		} else {
			$this->data['config_article_order'] = $this->config->get('config_article_order');
		}
		/*Date fotmat*/ 
		if (isset($this->request->post['config_article_date_format'])) {
			$this->data['config_article_date_format'] = $this->request->post['config_article_date_format'];
		} else {
			$this->data['config_article_date_format'] = $this->config->get('config_article_date_format');
		}
		/*Downloads*/ 
		if (isset($this->request->post['config_news_upload_allowed'])) {
			$this->data['config_news_upload_allowed'] = $this->request->post['config_news_upload_allowed'];
		} else {
			$this->data['config_news_upload_allowed'] = $this->config->get('config_news_upload_allowed');
		}
		if (isset($this->request->post['config_login_to_download'])) {
			$this->data['config_login_to_download'] = $this->request->post['config_login_to_download'];
		} else {
			$this->data['config_login_to_download'] = $this->config->get('config_login_to_download');
		}
		/*free download*/
		if (isset($this->request->post['config_free_download'])) {
			$this->data['config_free_download'] = $this->request->post['config_free_download'];
		} else {
			$this->data['config_free_download'] = $this->config->get('config_free_download');
		}	
				
		$this->load->model('news/download');
				
		if (isset($this->request->post['free_download'])) {
			$downloads = explode(',', $this->request->post['config_free_download']);
		} else {		
			$downloads = explode(',', $this->config->get('config_free_download'));
		}
		
		$this->data['downloads'] = array();
		
		foreach ($downloads as $download_id) {
			$download_info = $this->model_news_download->getFreeDownload($download_id);
			
			if ($download_info) {
				$this->data['downloads'][] = array(
					'download_id' => $download_info['download_id'],
					'name'       => $download_info['name']
				);
			}
		}	
		/*Comment allow*/ 
		if (isset($this->request->post['config_comment_email'])) {
			$this->data['config_comment_email'] = $this->request->post['config_comment_email'];
		} else {
			$this->data['config_comment_email'] = $this->config->get('config_comment_email');
		}
		if (isset($this->request->post['config_comment_status'])) {
			$this->data['config_comment_status'] = $this->request->post['config_comment_status'];
		} else {
			$this->data['config_comment_status'] = $this->config->get('config_comment_status');
		}
		if (isset($this->request->post['config_comment_approved'])) {
			$this->data['config_comment_approved'] = $this->request->post['config_comment_approved'];
		} else {
			$this->data['config_comment_approved'] = $this->config->get('config_comment_approved');
		}
		/*Article Image*/ 
		if (isset($this->request->post['article_description_limit'])) {
			$this->data['article_description_limit'] = $this->request->post['article_description_limit'];
		}elseif($this->config->get('article_description_limit')) {
			$this->data['article_description_limit'] = $this->config->get('article_description_limit');
		}else {
			$this->data['article_description_limit'] = 255;
		}
		
		if (isset($this->request->post['config_image_column_width'])) {
			$this->data['config_image_column_width'] = $this->request->post['config_image_column_width'];
		}elseif($this->config->get('config_image_column_width')) {
			$this->data['config_image_column_width'] = $this->config->get('config_image_column_width');
		}else {
			$this->data['config_image_column_width'] = 150;
		}
		
		if (isset($this->request->post['config_image_column_height'])) {
			$this->data['config_image_column_height'] = $this->request->post['config_image_column_height'];
		}elseif($this->config->get('config_image_column_height')) {
			$this->data['config_image_column_height'] = $this->config->get('config_image_column_height');
		}else {
			$this->data['config_image_column_height'] = 112;
		}
		
		if (isset($this->request->post['config_article_category_width'])) {
			$this->data['config_article_category_width'] = $this->request->post['config_article_category_width'];
		} else {
			$this->data['config_article_category_width'] = $this->config->get('config_article_category_width');
		}
		
		if (isset($this->request->post['config_article_category_height'])) {
			$this->data['config_article_category_height'] = $this->request->post['config_article_category_height'];
		} else {
			$this->data['config_article_category_height'] = $this->config->get('config_article_category_height');
		}
				
		if (isset($this->request->post['config_article_thumb_width'])) {
			$this->data['config_article_thumb_width'] = $this->request->post['config_article_thumb_width'];
		} else {
			$this->data['config_article_thumb_width'] = $this->config->get('config_article_thumb_width');
		}
		
		if (isset($this->request->post['config_article_thumb_height'])) {
			$this->data['config_article_thumb_height'] = $this->request->post['config_article_thumb_height'];
		} else {
			$this->data['config_article_thumb_height'] = $this->config->get('config_article_thumb_height');
		}
		
		if (isset($this->request->post['config_article_popup_width'])) {
			$this->data['config_article_popup_width'] = $this->request->post['config_article_popup_width'];
		} else {
			$this->data['config_article_popup_width'] = $this->config->get('config_article_popup_width');
		}
		
		if (isset($this->request->post['config_article_popup_height'])) {
			$this->data['config_article_popup_height'] = $this->request->post['config_article_popup_height'];
		} else {
			$this->data['config_article_popup_height'] = $this->config->get('config_article_popup_height');
		}
		
		if (isset($this->request->post['config_article_additional_width'])) {
			$this->data['config_article_additional_width'] = $this->request->post['config_article_additional_width'];
		} else {
			$this->data['config_article_additional_width'] = $this->config->get('config_article_additional_width');
		}
		
		if (isset($this->request->post['config_article_additional_height'])) {
			$this->data['config_article_additional_height'] = $this->request->post['config_article_additional_height'];
		} else {
			$this->data['config_article_additional_height'] = $this->config->get('config_article_additional_height');
		}
		
		if (isset($this->request->post['config_article_related_width'])) {
			$this->data['config_article_related_width'] = $this->request->post['config_article_related_width'];
		} else {
			$this->data['config_article_related_width'] = $this->config->get('config_article_related_width');
		}
		
		if (isset($this->request->post['config_article_related_height'])) {
			$this->data['config_article_related_height'] = $this->request->post['config_article_related_height'];
		} else {
			$this->data['config_article_related_height'] = $this->config->get('config_article_related_height');
		}
		


		if (isset($this->request->post['config_image_article_width'])) {
			$this->data['config_image_article_width'] = $this->request->post['config_image_article_width'];
		} else {
			$this->data['config_image_article_width'] = $this->config->get('config_image_article_width');
		}
		
		if (isset($this->request->post['config_image_article_height'])) {
			$this->data['config_image_article_height'] = $this->request->post['config_image_article_height'];
		} else {
			$this->data['config_image_article_height'] = $this->config->get('config_image_article_height');
		}
		/*general settings*/ 	
		
		$this->data['modules'] = array();
		
		if (isset($this->request->post['article_all_settings_module'])) {
			$this->data['modules'] = $this->request->post['article_all_settings_module'];
		} elseif ($this->config->get('article_all_settings_module')) { 
			$this->data['modules'] = $this->config->get('article_all_settings_module');
		}			
				
		$this->load->model('design/layout');
		
		$this->data['layouts'] = $this->model_design_layout->getLayouts();

		$this->template = 'module/article_setting_form.tpl';
		$this->children = array(
			'common/header',
			'news/shortcut_route',
			'news/shortcut_module',
			'common/footer'
		);
				
		$this->response->setOutput($this->render());
	}
	
	private function validate() {
		if (!$this->user->hasPermission('modify', 'module/article_all_settings')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}
			
		$this->load->model('news/utf8');
		if ($this->request->post['config_notification_mail']==1&&($this->model_news_utf8->utf8_strlen($this->request->post['config_notification_email']) > 96) || !preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['config_notification_email'])&&$this->request->post['config_notification_mail']==1||$this->request->post['config_comment_email']==1&&($this->model_news_utf8->utf8_strlen($this->request->post['config_notification_email']) > 96) || !preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['config_notification_email'])&&$this->request->post['config_comment_email']==1) {
      		$this->error['email'] = $this->language->get('error_email');
    	}
		/*General Setting*/ 	
		if (($this->request->post['article_description_limit']) < 3 || ($this->request->post['article_description_limit']) > 1024) {
			$this->error['article_description_limit'] = $this->language->get('error_article_description_limit');
		}
							
		if (!$this->request->post['config_article_category_width'] || !$this->request->post['config_article_category_height']) {
			$this->error['image_article_category'] = $this->language->get('error_image_article_category');
		} 
				
		if (!$this->request->post['config_article_thumb_width'] || !$this->request->post['config_article_thumb_height']) {
			$this->error['image_article_thumb'] = $this->language->get('error_image_article_thumb');
		}	
		
		if (!$this->request->post['config_article_popup_width'] || !$this->request->post['config_article_popup_height']) {
			$this->error['image_article_popup'] = $this->language->get('error_image_article_popup');
		}	
		
		if (!$this->request->post['config_image_column_width'] || !$this->request->post['config_image_column_height']) {
			$this->error['image_column'] = $this->language->get('error_image_column');
		}	
		if (!$this->request->post['config_image_article_width'] || !$this->request->post['config_image_article_height']) {
			$this->error['image_article'] = $this->language->get('error_image_article');
		}		
		
		if (!$this->request->post['config_article_additional_width'] || !$this->request->post['config_article_additional_height']) {
			$this->error['image_article_additional'] = $this->language->get('error_image_article_additional');
		}
		
		if (!$this->request->post['config_article_related_width'] || !$this->request->post['config_article_related_height']) {
			$this->error['image_article_related'] = $this->language->get('error_image_article_related');
		}
		/*general*/ 
		if (!$this->error) {
			return true;
		} else {
			return false;
		}	
	}	
	
	
	public function uninstall_module(){
		$this->load->model('news/install');
		$this->model_news_install->delete_module_setting();	
		$this->model_news_install->uninstall_module();	
		$this->session->data['success']='Success: Successfully drop Blog database!';
		$this->redirect($this->url->link('extension/module','token='.$this->session->data['token'], 'SSL'));
	}		
	public function optimize() {
		$this->load->model('news/install');
		$this->model_news_install->optimize();
		$this->session->data['success']='Success: Successfully Optimize News/Blog database!';
		$this->redirect($this->url->link('extension/module','token='.$this->session->data['token'], 'SSL'));
	}		
	public function empty_db() {
		$this->load->model('news/install');
		$this->model_news_install->empty_db();
		$this->model_news_install->delete_module_setting();
		$this->model_news_install->uninstall_module();	
		$this->session->data['success']='Success: Successfully empty Blog database!';
		$this->redirect($this->url->link('extension/module','token='.$this->session->data['token'], 'SSL'));
	}	
	public function drop_db(){
		$this->load->model('news/install');
		$this->model_news_install->drop_db();
		$this->model_news_install->delete_module_setting();
		$this->model_news_install->uninstall_module();
		//$this->model_news_install->delete_news_setting();	
		$this->session->data['success']='Success: Successfully drop Blog database!';
		$this->redirect($this->url->link('extension/module','token='.$this->session->data['token'], 'SSL'));
	}	
	public function uninstall() {
		$this->load->model('news/install');
		$this->model_news_install->uninstall();
	}
	public function install_sample(){
		$this->load->model('news/install');
		$this->model_news_install->installSampleNews();
		$this->session->data['success']='Success: Successfully installed sample database!';
		$this->redirect($this->url->link('module/article_all_settings/settings','token='.$this->session->data['token'], 'SSL'));
	}	
	public function hide_sample(){
		$this->load->model('news/install');
		$this->model_news_install->hideSampleNews();
		$this->redirect($this->url->link('module/article_all_settings/settings','token='.$this->session->data['token'], 'SSL'));
	}
	private function checkWrite(){
	$this->writefile('../index.php', '// Customer', '// Author Registry
include_once(DIR_SYSTEM . \'library/author.php\');
$registry->set(\'author\', new Author($registry));
// Customer', 1);
	}
	private function writefile($filename, $pattern, $replace, $repeat) {
		
		$real_filename = realpath($filename);		
		$content = $original_content = file_get_contents($real_filename);

		if($content === FALSE) {
			$this->error['warning'] = sprintf($this->language->get('error_notopen'),$filename);
			return;
		}
		
		if($repeat){
			$content = str_replace('// Author Registry' , '', $content);//preg_replace
		
			if($content !== $original_content){
				return;
			}
		}
			
		$content = str_replace($pattern, $replace, $content);//preg_replace
				
		if($content === NULL) {
			$this->error['warning'] = sprintf($this->language->get('error_regex'),$pattern);
			return;
		}
				
		if($content !== $original_content) {
				
			if(!is_writeable($real_filename)) {
				$this->error['warning'] = sprintf($this->language->get('error_notwrite'),$filename);
				return;
			} else {					
				$result = file_put_contents($real_filename, $content);
				if($result) {
					return;
				} else {
					$this->error['warning'] = sprintf($this->language->get('error_writefail'),$filename);
					return;
				}
			}
		}
	}
}
?>